package com.xiami.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

/*
创建者:虾米糖
*/
@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
    @Override//初始化,只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("过滤器初始化");

    }

    @Override//过滤器，每次请求都会调用
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("过滤器工作");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override//销毁，只调用一次
    public void destroy() {
        System.out.println("过滤器销毁");
    }
}
